export const getFileName = (s: string): string => {
  try {
    const url = new URL(s);
    const name: string = url.pathname?.split('/')?.pop() || '';
    return name;
  } catch (e) {
    return '';
  }
};
export const readImg = (file: File): Promise<HTMLImageElement> => {
  return new Promise((resolve, reject) => {
    const img: HTMLImageElement = new Image();
    const reader = new FileReader();
    reader.onload = function (e: any) {
      img.src = e.target?.result;
    };
    reader.onerror = function (e) {
      reject(e);
    };
    reader.readAsDataURL(file);
    img.onload = function () {
      resolve(img);
    };
    img.onerror = function (e) {
      reject(e);
    };
  });
};